//
//  CollectionViewCell.m
//  cm
//
//  Created by suyibaishan on 2017/10/26.
//  Copyright © 2017年 feihu. All rights reserved.
//

#import "CollectionViewCell.h"

@implementation CollectionViewCell

{
    UIView *goodsView;
    UIImageView *imgView;
    UILabel *titleLabel;
    UILabel *guideLabel;
    UILabel *priceLabel;
}

-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self constructUI];
    }
    return self;
}

-(void)constructUI
{
    goodsView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, (kScreenWidth-15)/2, (kScreenWidth - 15)/2+65)];
    goodsView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:goodsView];
    
    imgView = [[UIImageView alloc] init];
//    imgView.contentMode = UIViewContentModeScaleAspectFill;
//    imgView.clipsToBounds = YES;
    [goodsView addSubview:imgView];
    imgView.sd_layout
    .topSpaceToView(goodsView, 0)
    .leftSpaceToView(goodsView, 0)
    .widthIs((kScreenWidth-15)/2)
    .heightIs((kScreenWidth-15)/2);
//    imgView.backgroundColor = [UIColor redColor];
    
    titleLabel = [[UILabel alloc] init];
//    titleLabel.text = @"广州讴歌";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = [UIColor colorWithRed:0.01 green:0.03 blue:0.04 alpha:1];
    titleLabel.font = [UIFont systemFontOfSize:IS_IPHONE_8?13:IS_IPHONE_8PLUS?14:12];
    [goodsView addSubview:titleLabel];
    titleLabel.sd_layout
    .topSpaceToView(imgView, 1)
    .leftSpaceToView(goodsView, 0)
    .widthIs((kScreenWidth-15)/2)
    .heightIs(25);
    
    guideLabel = [[UILabel alloc] init];
//    guideLabel.textAlignment = NSTextAlignmentRight;
//    guideLabel.text = @"指导价¥9111.00";
    guideLabel.textColor = [UIColor blackColor];
    guideLabel.font = [UIFont systemFontOfSize:IS_IPHONE_8?12:IS_IPHONE_8PLUS?13:11];
    [goodsView addSubview:guideLabel];
    guideLabel.sd_layout
    .topSpaceToView(titleLabel, 0)
    .leftSpaceToView(goodsView, 5)
    .widthIs((kScreenWidth-15)/2-10)
    .heightIs(18);
    
    priceLabel = [[UILabel alloc] init];
//    priceLabel.textAlignment = NSTextAlignmentRight;
//    priceLabel.text = @"首付价¥9111.00";
    priceLabel.textColor = [UIColor colorWithRed:0.95 green:0 blue:0 alpha:1];
    priceLabel.font = [UIFont systemFontOfSize:IS_IPHONE_8?12:IS_IPHONE_8PLUS?13:11];
    [goodsView addSubview:priceLabel];
    priceLabel.sd_layout
    .topSpaceToView(guideLabel, 0)
    .leftSpaceToView(goodsView, 5)
    .widthIs((kScreenWidth-15)/2-10)
    .heightIs(15);
}

-(void)setModel:(CollectionModel *)model
{
    _model = model;
    priceLabel.hidden = model.type == 2;
    [imgView sd_setImageWithURL:[NSURL URLWithString:[kIMGURL stringByAppendingString:model.imgUrl]] placeholderImage:nil];
    titleLabel.text = model.productName;
    guideLabel.text = model.type == 2 ? [NSString stringWithFormat:@"需要积分%@",model.points] : [NSString stringWithFormat:@"指导价¥%.2f",model.unitPrice];
    priceLabel.text = [NSString stringWithFormat:@"首付价¥%.2f",model.downPayment];
}

@end
